/*
#          .,:,,,                                        .::,,,::.          
#        .::::,,;;,                                  .,;;:,,....:i:         
#        :i,.::::,;i:.      ....,,:::::::::,....   .;i:,.  ......;i.        
#        :;..:::;::::i;,,:::;:,,,,,,,,,,..,.,,:::iri:. .,:irsr:,.;i.        
#        ;;..,::::;;;;ri,,,.                    ..,,:;s1s1ssrr;,.;r,        
#        :;. ,::;ii;:,     . ...................     .;iirri;;;,,;i,        
#        ,i. .;ri:.   ... ............................  .,,:;:,,,;i:        
#        :s,.;r:... ....................................... .::;::s;        
#        ,1r::. .............,,,.,,:,,........................,;iir;        
#        ,s;...........     ..::.,;:,,.          ...............,;1s        
#       :i,..,.              .,:,,::,.          .......... .......;1,       
#      ir,....:rrssr;:,       ,,.,::.     .r5S9989398G95hr;. ....,.:s,      
#     ;r,..,s9855513XHAG3i   .,,,,,,,.  ,S931,.,,.;s;s&BHHA8s.,..,..:r:     
#    :r;..rGGh,  :SAG;;G@BS:.,,,,,,,,,.r83:      hHH1sXMBHHHM3..,,,,.ir.    
#   ,si,.1GS,   sBMAAX&MBMB5,,,,,,:,,.:&8       3@HXHBMBHBBH#X,.,,,,,,rr    
#   ;1:,,SH:   .A@&&B#&8H#BS,,,,,,,,,.,5XS,     3@MHABM&59M#As..,,,,:,is,   
#  .rr,,,;9&1   hBHHBB&8AMGr,,,,,,,,,,,:h&&9s;   r9&BMHBHMB9:  . .,,,,;ri.  
#  :1:....:5&XSi;r8BMBHHA9r:,......,,,,:ii19GG88899XHHH&GSr.      ...,:rs.  
#  ;s.     .:sS8G8GG889hi.        ....,,:;:,.:irssrriii:,.        ...,,i1,  
#  ;1,         ..,....,,isssi;,        .,,.                      ....,.i1,  
#  ;h:               i9HHBMBBHAX9:         .                     ...,,,rs,  
#  ,1i..            :A#MBBBBMHB #  .r1,..        ,..;3BMBBBHBB#Bh.     ..                    ....,,,,,i1;   
#   :h;..       .,..;,1XBMMMMBXs,.,, .. :: ,.               ....,,,,,,ss.   
#    ih: ..    .;;;, ;;:s58A3i,..    ,. ,.:,,.             ...,,,,,:,s1,    
#    .s1,....   .,;sh,  ,iSAXs;.    ,.  ,,.i85            ...,,,,,,:i1;     
#     .rh: ...     rXG9XBBM#M#MHAX3hss13&&HHXr         .....,,,,,,,ih;      
#      .s5: .....    i598X&&A&AAAAAA&XG851r:       ........,,,,:,,sh;       
#      . ihr, ...  .         ..                    ........,,,,,;11:.       
#         ,s1i. ...  ..,,,..,,,.,,.,,.,..       ........,,.,,.;s5i.         
#          .:s1r,......................       ..............;shs,           
#          . .:shr:.  ....                 ..............,ishs.             
#              .,issr;,... ...........................,is1s;.               
#                 .,is1si;:,....................,:;ir1sr;,                  
#                    ..:isssssrrii;::::::;;iirsssssr;:..                    
#                         .,::iiirsssssssssrri;;:.
*/
package com.itheima.queue;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * <dl>
 * <dd>描述: ~ QueueConfig</dd>
 * <dd>创建时间：  10:42 2020/10/23</dd>
 * <dd>创建人： guodong</dd>
 * <dt>版本历史: </dt>
 * <pre>
 * Date         Author         Version     Description
 * ------------------------------------------------------------------
 * 2020/10/23      guodong         1.0        1.0 Version
 * </pre>
 * </dl>
 */
@Component
public class QueueConfig {

    /*
        创建队列
     */
    @Bean
    public Queue queue(){
        return new Queue("hello");
    }
    /////////////////////////广播类型//////////////////////////////////
    @Bean
    public Queue fanoutA(){
        return new Queue("fanout.A");
    }
    @Bean
    public Queue fanoutB(){
        return new Queue("fanout.B");
    }
    @Bean
    public Queue fanoutC(){
        return new Queue("fanout.C");
    }
    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanout_ex");
    }
    /*
        此处参数需要注意与上面声明的bean name 一一对应
        bean name默认是方法名
     */
    @Bean
    Binding bindingFanoutA(Queue fanoutA, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutA).to(fanoutExchange);
    }
    @Bean
    Binding bindingFanoutB(Queue fanoutB, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutB).to(fanoutExchange);
    }
    @Bean
    Binding bindingFanoutC(Queue fanoutC, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutC).to(fanoutExchange);
    }

    /////////////////////////广播类型//////////////////////////////////


    /////////////////////////direct类型//////////////////////////////////

    @Bean
    public Queue directA(){
        return new Queue("direct.A");
    }
    @Bean
    public Queue directB(){
        return new Queue("direct.B");
    }
    @Bean
    public DirectExchange directExchange(){
        return new DirectExchange("direct_ex");
    }
    @Bean
    public Binding bindingDirectAHeima(Queue directA, DirectExchange directExchange){
        return BindingBuilder.bind(directA).to(directExchange).with("itheima");
    }

    @Bean
    public Binding bindingDirectACast(Queue directA, DirectExchange directExchange){
        return BindingBuilder.bind(directA).to(directExchange).with("itcast");
    }

    @Bean
    public Binding bindingDirectB(Queue directB, DirectExchange directExchange){
        return BindingBuilder.bind(directB).to(directExchange).with("itcast");
    }

    /////////////////////////direct类型//////////////////////////////////
    /////////////////////////topic类型//////////////////////////////////
    @Bean
    public Queue topicA(){
        return new Queue("topic.A");
    }
    @Bean
    public Queue topicB(){
        return new Queue("topic.B");
    }
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("topic_ex");
    }
    /*
       *:
        itheima.abc
        * 匹配不多不少一个词
    */
    @Bean
    public Binding bindingTopicA(Queue topicA, TopicExchange topicExchange){
        return BindingBuilder.bind(topicA).to(topicExchange).with("itheima.*");
    }
    /*
        #:
         itheima
         itheima.abc
         itheima.abc.itheihei
         # 匹配 >= 0个词
     */
    @Bean
    public Binding bindingTopicB(Queue topicB, TopicExchange topicExchange){
        return BindingBuilder.bind(topicB).to(topicExchange).with("itheima.#");
    }


    /////////////////////////topic类型//////////////////////////////////


}
